import {REQUEST_LOADING, LOGIN_FAILED, LOGIN_SUCCESS, RESET_FORM} from "../action/login-action";

const initialState = {
    isLoading: false,
    error: null,
};

const authenticationReducer = (state = initialState, action) => {
    switch (action.type) {
        case RESET_FORM: {
            return initialState;
        }
        case REQUEST_LOADING: {
            return Object.assign({}, state, {
                isLoading: true,
                error: null,
            });
        }
        case LOGIN_FAILED: {
            return Object.assign({}, state, {
                isLoading: false,
                error: action.error,
            })
        }
        case LOGIN_SUCCESS: {
            return Object.assign({}, state, {
                isLoading: false,
                error: null,
            })
        }
        default:
            return state;
    }
};

export default authenticationReducer;